#ifndef RGBDXTION_H
#define RGBDXTION_H
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <pcl/filters/extract_indices.h>
#include <pcl/io/openni2_grabber.h>
#include <pcl/io/openni_grabber.h>
#include <unistd.h>

class RGBD_xtion
{
public:
  RGBD_xtion();
  ~RGBD_xtion();
  void init();
  void fetchXYZ(pcl::PointCloud<pcl::PointXYZ> *XYZ);
  void fetchXYZRGB(pcl::PointCloud<pcl::PointXYZRGB> *XYZRGB);
  void fetchColorImage(cv::Mat &image);
  void fetchDepthImage(cv::Mat &image);
private:
  void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud);
  void image_cb_ (const boost::shared_ptr<pcl::io::OpenNI2Grabber::Image>& img);
  void depth_cb_ (const boost::shared_ptr<pcl::io::OpenNI2Grabber::DepthImage> &img);
  void getFrame (const boost::shared_ptr<pcl::io::OpenNI2Grabber::Image> &img);
  void run();
  void stop();
  bool update_cloud;
  bool update_image;
  bool update_depth;
  pcl::Grabber* interface;
  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_sence;
  cv::Mat rgb_image;
  cv::Mat depth_image;
};

#endif // RGBDXTION_H
